<template>
    <div class="checkTel">
        <van-nav-bar title="标题" left-text="返回" left-arrow @click-left="onClickLeft" />
        <div class="content">
            <van-field v-model="tel" name="手机号" placeholder="手机号" />
            <div style="margin: 16px;">
                <van-button round block type="primary" :disabled="!flag" class="custom_btn" @click="checkPhone">
                    提交
                </van-button>
            </div>
        </div>
    </div>
</template>
<script>
import { doChecktel } from '@/api/user';
    export default {
        data(){
            return{
                tel:'19037530724'
            }
        },
        computed:{
           flag(){
            return /^1[35789]\d{9}$/.test(this.tel)
           }
        },
        methods:{
            onClickLeft(){
                history.back()
            },
            checkPhone(){
                doChecktel({tel:this.tel}).then(res=>{ 
                    if(res.data.code=='10005'){
                        return showToast('该用户已被注册')
                    }
                    localStorage.setItem('tel',this.tel)
                    this.$router.push('/user/sendmsg')
                })
            }
        }
    }
</script>
<style lang="less" scoped>
.custom_btn {
    background: pink;
    border: 0;
}
</style>